﻿using System.Windows.Controls;
using System.Windows.Navigation;

using Lastfm7.Services;
using Lastfm7.ViewModels;
using Microsoft.Phone.Controls;

namespace Lastfm7
{
    public partial class ProfilePage : PhoneApplicationPage
    {
        public ProfilePage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            DataContext = App.Current.ProfileViewModel;

            LastfmService.Instance.TryRetrieveTopArtists();
        }

        void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
                return;

            var item = e.AddedItems[0] as MenuItemViewModel;
            if (item == null)
                return;

            NavigationService.Navigate(item.GetPageUri());
        }
    }
}